define(["jquery", "easy-admin"], function ($, ea) {
    var form = layui.form;
    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'user.user_real/index',
        add_url: 'user.user_real/add',
        edit_url: 'user.user_real/edit',
        delete_url: 'user.user_real/delete',
        export_url: 'user.user_real/export',
        modify_url: 'user.user_real/modify',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'id',search: false},
                    {field: 'cate.title', title: '用户姓名'},
                    {field: 'id_card', title: '身份证号', search: false},
                    {field: 'z_image', title: '身份证正面', templet: ea.table.image, search: false},
                    {field: 'f_image', title: '身份证反面', templet: ea.table.image, search: false},
                    {field: 'status', title: '是否审核 ',selectList: {0: '待审核', 1: '已审核'}, align:'center',templet: '#typeConvert',sort: true}
                ]],
            });
            ea.listen();
            form.on('switch(status)', function(obj){
                var id = obj.elem.getAttribute("mid"); // 当行ID
                var value = this.checked ? '1' : '0'; // 选中状态
                $.ajax({
                    url: "modify",
                    type: "post",
                    data: {id: id ,value: value,field:'status'}, // 参数
                    success: function(data) {
                        layer.msg(data.msg, {icon: 6},function(){
                            window.location.reload();
                        });
                    },
                    error: function(xhr) {
                        layer.msg('系统错误，请联系管理员');
                    }
                });
            });
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});